# 引入requests
import requests
from bs4 import BeautifulSoup

from db import session_scope
from db import chapters

# 实例化一个request请求，并返回内容
r = requests.get("https://www.xbiquge.la/25/25858/")
# print(bytes.decode(r.content))
# BeautifulSoup 美味的汤 ，lxml 解析html
# 解析网页内容
soup = BeautifulSoup(r.content,"lxml")
# print(soup)
# 获取id=list 
indexlist = soup.find(id="list")
# print(indexlist)
links = indexlist.find_all("a")
# print(links)
with session_scope() as se:
    for item in links:
        indexItemContent = item.get_text()
        print(indexItemContent)
        chapter = chapters()
        chapter.chapter_name =  indexItemContent
        se.add(chapter)


